/*
 * Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 * This file is part of e3time.
 *
 * e3time is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * e3time is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with e3time. If not, see <https://www.gnu.org/licenses/>.
 */

package e3time

import "gitee.com/ameise84/e3ds/heap"

type TimerHandler interface {
	OnTimer(_ Timer, fireAt Time)
}

type WithUniqueID = heap.WithUniqueID[uint64]

type Timer interface {
	Context() any
	Reset(dur Duration, repeat ...int) (Time, bool) //重置成功,返回下一次执行的时间,如果原来的定时任务还存在,原任务将会被kill(如果已经被触发,还是会触发),
	Pause()                                         //暂停后可继续持有对象,直到调用Reset 或 Revert
	Revert()
}

type TimerHolder interface {
	NewTimer(cb TimerHandler, ctx any, dur Duration) Timer
	NewTimerWithDoTime(cb TimerHandler, ctx any, doTime Time) Timer
	NewTick(cb TimerHandler, ctx any, dur Duration, repeat int) Timer
	NewTickWithFirstAt(cb TimerHandler, ctx any, fireAt Time, dur Duration, repeat int) Timer
	KillTimerWithID(uint64)
	KillTimer(Timer) //释放Timer后,对象不能在使用,应用层不可继续操作该对象
	KillAllTimers()
}
